<?php if($this->router->fetch_method() === 'weibologin'): ?>
<div class="regiter-choose">
    <p>您尚未绑定账号，请选择</p>
    <div class="regiter-choose-btn">
        <a class="signIn" href="javascript:;">已有易米账号，立即绑定微博</a>
        <a href="<?php echo base_url('home/weiboregister'); ?>" style="float:right;line-height: 30px;">没有易米账号，微博注册账号</a>
    </div>
    <div class="clearfix"></div>
</div>
<?php endif; ?>

<?php if($this->router->fetch_method() === 'weiboregister'): ?>
<div class="regiter-infor">
    <div class="regiter-infor-portrait"><img src="<?php echo $weiboUserInfo['photos']; ?>" /></div>
    <div class="regiter-infor-name">昵 称：<span><?php echo $weiboUserInfo['name']; ?></span></div>
    <form id="register-form">
        <div class="input-group">
            <input type="email" name="register_name" id="register_name" class="form-control" minlength="3" maxlength="30" required="required" placeholder="注册邮箱"/>
        </div>
        <div class="input-group">
            <input type="password" name="register_password" class="form-control" maxlength="30" required="required" placeholder="注册密码"/>
        </div>
        <div class="input-group">
        <input type="text" name="register_captcha" id="register-captcha" class="form-control" minlength="4" maxlength="30" required="required" placeholder="请填写验证码" style="width:180px;"/>
        <div class="register-captcha-img">
            <?php if (isset($captcha) && isset($captcha['image'])) echo $captcha['image']; ?>
        </div>
        </div>
        <div class="input-group">
            <input type="submit" class="btn btn-success form-control" value="注 册" style="margin-top:10px;"/>
        </div>
    </form>
</div>
<?php endif; ?>

<script>
    $(function () {
        $.AutoComplete('#register_name');

        $('.register-captcha-img').click(function () {
            $.getJSON('<?php echo base_url('api/getCaptcha');?>', function (rsp) {
                try {
                    switch (rsp.type) {
                        case 'success':
                            $('.register-captcha-img').html(rsp.data);
                            break;
                        default :
                            noty({type: rsp.type, text: rsp.message});
                            break;
                    }
                } catch (ex) {
                    noty({type: 'error', text: '发生内部错误，请联系管理员'});
                    throw ex;
                }
            });
        });
        $("#register-form").validate({
            submitHandler: function (form) {
                $.ajax({
                    url: '<?php echo base_url('api/register/weibo');?>',
                    type: 'post',
                    data: $(form).serialize(),
                    dataType:"json",
                    beforeSend:function(){
                        showProgressNoty();
                    },
                    complete: function () {
                        closeProgressNoty();
                    },
                    success: function (jsonrsp) {
                        try {
                            noty({type: jsonrsp.type, text: '注册成功！', callback: {
                                afterClose: function () {
                                    switch (jsonrsp.type) {
                                        case 'success':
                                            noty({
                                                type:'success',
                                                text:jsonrsp.message,
                                                buttons: [
                                                    {
                                                        addClass: 'btn btn-sm btn-danger', text: '确定',
                                                        onClick: function ($noty) {
                                                            $noty.close();
                                                            window.location.href=jsonrsp.mail_url;
                                                        }
                                                    },
                                                    {
                                                        addClass: 'btn btn-sm btn-default', text: '取消',
                                                        onClick: function ($noty) {
                                                            $noty.close();
                                                            window.location.href='<?php echo base_url('home') ?>';
                                                        }
                                                    }
                                                ]
                                            });
                                            break;
                                        case 'fail':
                                            noty({type:rsp.type,text:rsp.message});
                                        default:
                                            break;
                                    }
                                }
                            }});
                        } catch (ex) {
                            noty({type: 'error', text: '发生内部错误，请联系管理员'});
                            throw ex;
                        }
                    }
                });
            }
        });
    });
</script>